import httpRequest from "./request"
import {ResponseHomeIconList} from "@/app/model/homeIconModel";

let baseUrl = "https://jybapipub.iqdii.com";
import axios from 'axios';
import {ServerResponse} from "node:http";
import {ApiResponse} from "@/app/model/Servers";
import {ResponseAdlist} from "@/app/model/ResponseAdlist";

export const getServiceList = async ():Promise<string> => {
    try {
        const response = await axios.get(baseUrl+'/jybapp/Config/HomeIconList?uid=&session=2F22AF40A25C23B7F8883F17&org=org_jyb_mob&version=6.0&network=wifi&ver=8.3.63&lang=chs&mobile=android&terminal=android&HarmonyOS=true',
            {
                headers: {
                    "JybHeader": "eyJTZXNzaW9uSWQiOiIyRjIyQUY0MEEyNUMyM0I3Rjg4ODNGMTciLCJVc2VySWQiOiIiLCJPcmdD%0Ab2RlIjoib3JnX2p5Yl9tb2IifQ%3D%3D%0A",
                },
                params:{
                    "Location": 9,
                    "mode": 'android',
                    "new": 0,
                    "source":""
                }
        });
        return response.data;
    } catch (error) {
        console.error('Error during the request', error);
        throw error;
    }
};
export const fetchServerInfo = async (): Promise<ApiResponse> => {
    try {
        const response = await axios.get<ApiResponse>('https://jybapisit.iqdii.com/jybapp/other/servers',
            {  });
        return response.data;
    } catch (error) {
        console.error('Error fetching server info:', error);
        throw error;
    }
};

/**
 * 获取首页接口
 */
function getHomeIconList() {
    return httpRequest.post<ResponseHomeIconList>(
        {
            url: baseUrl + "/jybapp/Config/HomeIconList?uid=&session=2F22AF40A25C23B7F8883F17&org=org_jyb_mob&version=6.0&network=wifi&ver=8.3.63&lang=chs&mobile=android&terminal=android&HarmonyOS=true",
            data:{
                "Location": 9,
                "mode": 'android',
                "new": 0,
                "source":""
            },
            headers: {
                "JybHeader": "eyJTZXNzaW9uSWQiOiIyRjIyQUY0MEEyNUMyM0I3Rjg4ODNGMTciLCJVc2VySWQiOiIiLCJPcmdD%0Ab2RlIjoib3JnX2p5Yl9tb2IifQ%3D%3D%0A",
            },
            checkResultCode: false,
        }
    )
}
function getHomeADList() {
    return httpRequest.post<ResponseAdlist>(
        {
            url: baseUrl + "/jybapp/ConfigService/QueryAdvertisementList?uid=&org=org_jyb_mob&version=6.0&network=wifi&ver=8.3.60&lang=chs&mobile=android&terminal=android&terminaltype=android&HarmonyOS=true",
            data:{
                "datatype": 35,
                "resourcetype": '',
                "org": 'jyb',
                "resolution": '1080p'
            },
            headers: {
                "JybHeader": "eyJTZXNzaW9uSWQiOiIyRjIyQUY0MEEyNUMyM0I3Rjg4ODNGMTciLCJVc2VySWQiOiIiLCJPcmdD%0Ab2RlIjoib3JnX2p5Yl9tb2IifQ%3D%3D%0A",
            },
            checkResultCode: false,
        }
    )
}
function getLiveList() {
    return httpRequest.get<ResponseLiveListData>(
        {
            url: 'https://cloudapi.iqdii.com/videoColumn/smallGoose/GetLiveVideoPlayBackList?uid=&org=org_jyb_mob&version=6.0&network=wifi&ver=8.3.63&lang=chs&mobile=android&terminal=android&terminaltype=android&HarmonyOS=true&orgCode=JYB&pageSize=4&sort=0',
            headers: {
                "JybHeader": "eyJTZXNzaW9uSWQiOiIyRjIyQUY0MEEyNUMyM0I3Rjg4ODNGMTciLCJVc2VySWQiOiIiLCJPcmdD%0Ab2RlIjoib3JnX2p5Yl9tb2IifQ%3D%3D%0A",
            },
            checkResultCode: false,
        }
    )
}




export default {
    getHomeIconList,
    getServiceList,
    fetchServerInfo,
    getHomeADList,
    getLiveList
}
